<template>
	<view>
		<view class="seid">
			<text>设备码图片</text>
			<view @click="yingye()">
				<image :src="imghsy ||'../../static/logo.png'" mode=""></image>
			</view>
		</view>
		<view class="seid">
			<text>设备码</text>
			<input type="text" placeholder="请输入设备码" v-model="jqma">
		</view>
		<view class="seidou" @click="bangding">绑定</view>
	</view>
</template>

<script>
	import {sbm} from '../../common/api/dy.js'
	import {user} from "../../common/api/base.js"
	export default {
		data() {
			return {
				jqma:"",
				imgs:"",
				us:"",
				imghsy:""
			};
		},
		onShow() {
			this.geren()
		},
		computed:{
			projectType(){
				return this.$store.state.projectType
			}
		},
		methods:{
			geren(){
				user({}).then(res=>{
					if(res.code=="1"){
						this.us=res.data
						this.imghsy=res.data.img
						this.jqma=res.data.devid
					}
				})
			},
			bangding(){
				sbm({devid:this.jqma,img:this.imghsy}).then(res=>{
					if(res.code=='1'){
					  uni.$u.toast("设备绑定成功！")
					  setTimeout(function(){
						   uni.navigateBack()
					  },2000)
					}
				})
			},
			yingye(){
				let that=this
				uni.chooseImage({
					count:1, 
					sizeType: ['original', 'compressed'], 
					sourceType: ['album'],
					  success: function (res) {
						var tempFilePaths = res.tempFilePaths;
						uni.uploadFile({
							url: 'https://shop.huizhuyl.com/api/user/uploadImage',
							filePath: tempFilePaths[0],
							method: 'POST',
							name: 'file',
							success: (res) => {
								that.imgs=JSON.parse(res.data)
								that.imghsy=that.imgs.data
								uni.$u.toast("上传成功")
							}
						});
					  }
				});
			},
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #F7F8FA;
	}
	.seid{
		width:95%;
		margin: 0 auto;
		height:80rpx;
		display:flex;
		justify-content: space-between;
		align-items:center;
		box-shadow:0px 0px 10rpx #ccc;
		margin-top:40rpx;
		padding:20rpx;
		box-sizing: border-box;
		border-radius:6rpx;
		background-color:#fff;
		font-size:24rpx;
		view{
			width:400rpx;
			text-align: right;
		}
		image{
			width:70rpx;
			height:70rpx;
		}
		input{
			width:300rpx;
			border:none;
			text-align:right;
		}
	}
	.seidou{
		width:95%;
		margin: 0 auto;
		height:80rpx;
		display:flex;
		justify-content: center;
		align-items:center;
		box-shadow:0px 0px 10rpx #ccc;
		background-color: darkgreen;
		color:#fff;
		border-radius:6rpx;
		margin-top:80rpx;
	}
	
</style>